package jdbc;

import java.sql.*;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {

        UserInfo userInfo= InputUtil.getInputObject(new UserInfo(),"欢迎注册","注册");
        System.out.println(userInfo);
        //加载驱动 第一步
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取连接 与数据库 第二步
        Connection connection= DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
               "123456"
        );
       System.out.println("连接成功");
       //创建执行sql语句的对象 第三部
        Statement statement=connection.createStatement();

        //第四部 执行sql语句
        String sql="INSERT INTO userinfo(username,password,nickname,age )"+
                "VALUES('"+ userInfo.getUsername()+"',"+userInfo.getUsername()+","+userInfo.getUsername()+","+userInfo.getUsername()+")";
        System.out.println(sql);
        statement.executeUpdate(sql);
        System.out.println("注册成功");
        //第五步 关闭连接
        connection.close();

    }
}
